package com.fengyi.library.service;

import com.fengyi.library.model.Book;
import com.fengyi.library.model.Loan;
import com.fengyi.library.model.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import java.util.List;

public interface LoanService {
    Loan findById(Integer id);
    Page<Loan> findLoansByUser(User user, Pageable pageable);
    List<Loan> findCurrentLoansByUser(User user);
    List<Loan> findReturnedLoansByUser(User user);
    List<Loan> findOverdueLoansByUser(User user);
    List<Loan> findLoansByBook(Book book);
    List<Loan> findOverdueLoans();
    Loan borrowBook(User user, Book book, int loanDays);
    Loan returnBook(Integer loanId);
    boolean hasUserBorrowedBook(User user, Book book);
    long countCurrentBorrowedBooks(User user);
    long countReturnedBooks(User user);
    long countOverdueBooks(User user);
    Page<Loan> findAllLoans(Pageable pageable);
    
    /**
     * 搜索借阅记录
     * 根据关键词搜索借阅记录，可以匹配用户名、图书标题等
     * 
     * @param keyword 搜索关键词
     * @param pageable 分页参数
     * @return 分页的借阅记录
     */
    Page<Loan> searchLoans(String keyword, Pageable pageable);

    Page<Loan> findAllOverdueLoans(Pageable pageable);
    
    /**
     * 更新借阅状态
     * 检查并更新所有借阅的状态，特别是将过期的借阅标记为逾期状态
     */
    void updateLoanStatus();
}
